import request from "@/utils/request";
import {
  ProjectGuaranteeAccountEditForm,
  ProjectGuaranteePaymentEditForm,
  ProjectGuaranteePaymentAuditForm,
  ProjectGuaranteeRefundEditForm,
  ProjectGuaranteeRefundAuditForm,
  ProjectGuaranteeIncomeEditForm,
  ProjectGuaranteeExpenditureEditForm,
  QueryPaymentForm,
} from "./types";
const currentSystem = localStorage.getItem("usertypeName");

/********* 保证金账户 start***********/
/**
 * 获取保证金账户分页
 *
 * @param data
 */
export function QueryProjectGuaranteeAccount(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/account/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/account/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/account/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/account/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/account/page`;
      break;
    default:
      url = `/api/v1/sysuser/guarantee/account/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取保证金账户
 * @param data
 */
export function GetProjectGuaranteeAccount(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/account`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/account`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/account`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/account`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/account`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}
/**
 * 创建保证金账户
 */
export function CreateProjectGuaranteeAccount(data: ProjectGuaranteeAccountEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/account/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/account/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/account/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/account/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/account/create`;
      break;
    default:
      break;
  }

  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 修改保证金账户
 * @param data
 */
export function UpdateProjectGuaranteeAccount(data: ProjectGuaranteeAccountEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/account/update`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/account/update`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/account/update`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/account/update`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/account/update`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}
/**
 * 删除保证金账户
 * @param ids
 * @returns
 */
export function DeleteProjectGuaranteeAccount(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/account`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/account`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/account`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/account`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/account`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${ids}`,
    method: "delete",
  });
}
/********* 保证金账户 end***********/

/********* 保证金账户缴纳信息 start***********/

/**
 * 获取保证金账户分页
 *
 * @param data
 */
export function QueryProjectGuaranteePayment(data: QueryPaymentForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment/page`;
      break;
    default:
      url = `/api/v1/sysuser/guarantee/payment/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取保证金账户
 * @param data
 */
export function QueryActivePaymentPage(data: QueryPaymentForm) {
  return request({
    url: `/api/v1/sysuser/guarantee/payment/active_page`,
    method: "get",
    params: data,
  });
}

/**
 * 获取保证金账户
 * @param data
 */
export function GetProjectGuaranteePayment(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}

/**
 * 通过账号Id获取所有的缴纳信息
 * @param id
 * @returns
 */
export function GetProjectGuaranteePaymentsByAccountId(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment/list`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment/list`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment/list`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment/list`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment/list`;
      break;
    default:
      break;
  }

  return request({
    url: url + `/${id}`,
    method: "get",
  });
}

/**
 * 创建保证金账户
 */
export function CreateProjectGuaranteePayment(data: ProjectGuaranteePaymentEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment/create`;
      break;
    default:
      break;
  }

  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 修改保证金账户
 * @param data
 */
export function UpdateProjectGuaranteePayment(data: ProjectGuaranteePaymentEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment/update`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment/update`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment/update`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment/update`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment/update`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 审核保证金账户
 * @param data
 */
export function AuditProjectGuaranteePayment(data: ProjectGuaranteePaymentAuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment/audit`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment/audit`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment/audit`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment/audit`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment/audit`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}
/**
 * 删除项目保证金缴纳信息
 * @param ids
 */
export function DeleteProjectGuaranteePayment(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/payment`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/payment`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/payment`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/payment`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/payment`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${ids}`,
    method: "delete",
  });
}

/********* 保证金账户缴纳西信息 end***********/

/********* 保证金账户缴纳退还信息 start***********/

/**
 * 获取保证金退还分页
 *
 * @param data
 */
export function QueryProjectGuaranteeRefund(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/refund/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/refund/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/refund/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/refund/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/refund/page`;
      break;
    default:
      url = `/api/v1/sysuser/guarantee/refund/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取需要退还的缴纳信息Id
 */
export function GetNeedRefundPayment() {
  return request({
    url: `/api/v1/manager/guarantee/refund/need_apply`,
    method: "get",
  });
}

/**
 * 获取保证金退还信息
 * @param data
 */
export function GetProjectGuaranteeRefund(id: number, guaranteePaymentId?: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/refund`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/refund`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/refund`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/refund`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/refund`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "get",
    params: { guaranteePaymentId: guaranteePaymentId },
  });
}
/**
 * 申请保证金退还
 */
export function ApplyProjectGuaranteeRefund(data: ProjectGuaranteeRefundEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/refund/apply`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/refund/apply`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/refund/apply`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/refund/apply`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/refund/apply`;
      break;
    default:
      break;
  }

  return request({
    url: url,
    method: "post",
    data: data,
  });
}
/**
 * 审核保证金账户退还
 * @param data
 */
export function AuditProjectGuaranteeRefund(data: ProjectGuaranteeRefundAuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/refund/audit`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/refund/audit`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/refund/audit`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/refund/audit`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/refund/audit`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/********* 保证金账户缴纳退还信息 end***********/

/********* 账户收入信息 start***********/

/**
 * 获取收入信息列表
 *
 * @param data
 */
export function QueryProjectGuaranteeIncome(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/income/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/income/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/income/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/income/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/income/page`;
      break;
    default:
      url = `/api/v1/sysuser/guarantee/income/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 收入信息表单数据
 * @param data
 */
export function GetProjectGuaranteeIncome(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/income`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/income`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/income`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/income`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/income`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}
/**
 * 新增账户收入信息
 */
export function CreateProjectGuaranteeIncome(data: ProjectGuaranteeIncomeEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/income/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/income/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/income/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/income/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/income/create`;
      break;
    default:
      break;
  }

  return request({
    url: url,
    method: "post",
    data: data,
  });
}
/**
 * 删除收入信息
 * @param data
 */
export function DeleteProjectGuaranteeIncome(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/income`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/income`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/income`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/income`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/income`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${ids}`,
    method: "delete",
  });
}

/**
 * 导出收入明细
 */
export function ExportProjectGuaranteeIncome(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/income/export`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/income/export`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/income/export`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/income/export`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/income/export`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
    responseType: "arraybuffer",
  });
}

/********* 账户收入信息 end***********/

/********* 账户支出信息 start***********/

/**
 * 获取支出信息列表
 *
 * @param data
 */
export function QueryProjectGuaranteeExpenditure(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure/page`;
      break;
    default:
      url = `/api/v1/sysuser/guarantee/expenditure/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 支出信息表单数据
 * @param data
 */
export function GetProjectGuaranteeExpenditure(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}

/**
 * 支出信息表单数据
 * @param data
 */
export function GetProjectGuaranteeExpenditureDetail(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure/detail`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure/detail`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure/detail`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure/detail`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure/detail`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${id}`,
    method: "get",
  });
}

/**
 * 新增账户支出信息
 */
export function CreateProjectGuaranteeExpenditure(data: ProjectGuaranteeExpenditureEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure/create`;
      break;
    default:
      break;
  }

  return request({
    url: url,
    method: "post",
    data: data,
  });
}
/**
 * 删除支出信息
 * @param data
 */
export function DeleteProjectGuaranteeExpenditure(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure`;
      break;
    default:
      break;
  }
  return request({
    url: url + `/${ids}`,
    method: "delete",
  });
}

/**
 * 下载导入模板
 */
export function DownloadProjectGuaranteeExpenditureTemplate() {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure/exportTemplate`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure/exportTemplate`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure/exportTemplate`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure/exportTemplate`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure/exportTemplate`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 初始化导入文件数据
 */
export function InitExpenditureDetail(attachmentId: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/guarantee/expenditure/import`;
      break;
    case "Corp":
      url = `/api/v1/corp/guarantee/expenditure/import`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/guarantee/expenditure/import`;
      break;
    case "Manager":
      url = `/api/v1/manager/guarantee/expenditure/import`;
      break;
    case "Commander":
      url = `/api/v1/commander/guarantee/expenditure/import`;
      break;
    default:
      break;
  }
  return request({
    url: url,
    method: "get",
    params: {
      attachmentId: attachmentId,
    },
  });
}

/********* 账户支出信息 end***********/
